package com.heba.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.google.android.material.tabs.TabLayout;
import com.heba.bean.product.ItemProductCompareObject;
import com.heba.greenmulu.R;

import java.util.List;

/**
 * 食品含量对比Adapter
 * <p>
 * Created by jason on 2019/2/26.
 */

public abstract class ItemComparisonAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<ItemProductCompareObject> list;

    public enum ITEM_TYPE {
        ITEM_TYPE_HEADER,
        ITEM_TYPE_ITEM
    }

    public ItemComparisonAdapter(Context context, List<ItemProductCompareObject> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//        Debug.Log(tag, "onCreateViewHolder");
        LayoutInflater inflater = LayoutInflater.from(context);
        if (viewType == ITEM_TYPE.ITEM_TYPE_HEADER.ordinal()) {
            return new HeaderHolder(inflater.inflate(R.layout.item_comparison_header, parent, false));
        }
        return new ItemHolder(inflater.inflate(R.layout.item_comparison, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
//        Debug.Log(tag, "onBindViewHolder");
        convert(holder, list.get(position), position);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return ITEM_TYPE.ITEM_TYPE_HEADER.ordinal();
        } else {
            return ITEM_TYPE.ITEM_TYPE_ITEM.ordinal();
        }
    }

    public abstract void convert(RecyclerView.ViewHolder holder, ItemProductCompareObject data, int position);

    /**
     * HeaderHolder
     */
    public class HeaderHolder extends RecyclerView.ViewHolder {

//        public ImageView img_photo;
//        public TextView txt_title;
//        public TextView txt_content;
//        public TextView txt_serving_size;
        //        public ImageView img_collect;
//        public ImageView img_share;
//        public ImageView img_report;

        public ConstraintLayout view_category;
        public ConstraintLayout view_origin;
        public ConstraintLayout view_taste;
        public ConstraintLayout view_tag;
        public ConstraintLayout view_ingredient;
        public ConstraintLayout view_allergen;
        public ConstraintLayout view_others;

        public TabLayout tabLayout;
        public LinearLayout linear_per_view;
        public TextView txt_less_energy;
        public TextView txt_more_protein;
        public TextView txt_less_fat;
        public TextView txt_less_sat_fat;
        public TextView txt_less_carb;
        public TextView txt_less_sugar;
        public TextView txt_less_sodium;
        public ImageView img_filter;
        public LinearLayout linear_option_filter_view;   //一般筛选View
        public Spinner spinner;

        public HeaderHolder(View itemView) {
            super(itemView);
//            img_photo = itemView.findViewById(R.id.img_photo);
//            txt_title = itemView.findViewById(R.id.txt_title);
//            txt_content = itemView.findViewById(R.id.txt_content);
//            txt_serving_size = itemView.findViewById(R.id.txt_serving_size);
//            img_collect = itemView.findViewById(R.id.img_collect);
//            img_share = itemView.findViewById(R.id.img_share);
//            img_report = itemView.findViewById(R.id.img_report);
            view_category = itemView.findViewById(R.id.view_category);
            view_origin = itemView.findViewById(R.id.view_origin);
            view_taste = itemView.findViewById(R.id.view_taste);
            view_tag = itemView.findViewById(R.id.view_tag);
            view_ingredient = itemView.findViewById(R.id.view_ingredient);
            view_allergen = itemView.findViewById(R.id.view_allergen);
            view_others = itemView.findViewById(R.id.view_others);
            tabLayout = itemView.findViewById(R.id.tablayout);
            linear_per_view = itemView.findViewById(R.id.linear_per_view);
            txt_less_energy = itemView.findViewById(R.id.txt_less_energy);
            txt_more_protein = itemView.findViewById(R.id.txt_more_protein);
            txt_less_fat = itemView.findViewById(R.id.txt_less_fat);
            txt_less_sat_fat = itemView.findViewById(R.id.txt_less_sat_fat);
            txt_less_carb = itemView.findViewById(R.id.txt_less_carb);
            txt_less_sugar = itemView.findViewById(R.id.txt_less_sugar);
            txt_less_sodium = itemView.findViewById(R.id.txt_less_sodium);
            img_filter = itemView.findViewById(R.id.img_filter);
            linear_option_filter_view = itemView.findViewById(R.id.ll_filter_view);
            spinner = itemView.findViewById(R.id.spinner);
        }
    }

    /**
     * ItemHolder
     */
    public class ItemHolder extends RecyclerView.ViewHolder {

        public ConstraintLayout constrain_view;
        public ConstraintLayout constrain_view1;
        public LinearLayout linear_per_view;
        public ImageView img_photo;
        public TextView txt_product;
        public TextView txt_content;
        public ImageView img_photo1;
        public TextView txt_product1;
        public TextView txt_content1;
        public TextView txt_serving_size;
        public TextView txt_product_go;
//        public ImageView img_collect;
//        public ImageView img_share;
//        public ImageView img_report;

        public ItemHolder(View itemView) {
            super(itemView);
            constrain_view = itemView.findViewById(R.id.constrain_view);
            constrain_view1 = itemView.findViewById(R.id.constrain_view1);
            linear_per_view = itemView.findViewById(R.id.linear_per_view);
            img_photo = itemView.findViewById(R.id.img_photo);
            txt_product = itemView.findViewById(R.id.txt_product);
            txt_content = itemView.findViewById(R.id.txt_content);
            img_photo1 = itemView.findViewById(R.id.img_photo1);
            txt_product1 = itemView.findViewById(R.id.txt_product1);
            txt_content1 = itemView.findViewById(R.id.txt_content1);
            txt_serving_size = itemView.findViewById(R.id.txt_serving_size);
            txt_product_go = itemView.findViewById(R.id.txt_product_go);
//            img_collect = itemView.findViewById(R.id.img_collect);
//            img_share = itemView.findViewById(R.id.img_share);
//            img_report = itemView.findViewById(R.id.img_report);
        }
    }
}
